<template>
    <div class="table-box">
        <el-table :data="tableList" :height="height">
        <el-table-column align="center" label="分量" prop="comp" />
        <el-table-column align="center" label="分量名称" prop="compname"/>
        <el-table-column align="center" label="类型" prop="valueType">
            <template slot-scope="scope">
            <p v-if="scope.row.valueType == 0">初始值</p>
            <p v-if="scope.row.valueType == 1">中间值</p>
            <p v-if="scope.row.valueType == 2">结果值</p>
            </template>
        </el-table-column>
        <el-table-column align="center" label="仪器上限" prop="upperLimit">
            <template slot-scope="scope">
            <p class="blueText">{{ scope.row.upperLimit }}</p>
            </template>
        </el-table-column>
        <el-table-column align="center" label="仪器下限" prop="lowerLimit">
            <template slot-scope="scope">
            <p class="redText">{{ scope.row.lowerLimit }}</p>
            </template>
        </el-table-column>
        <el-table-column align="center" label="测点分类上限" prop="lowerLimit" v-if="isSet">
           <template slot-scope="scope">
            <el-input size="small" v-model="scope.row.max" placeholder="请输入" @blur="handleSaveSetComp(scope.row)"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="测点分类下限" prop="lowerLimit" v-if="isSet">
            <template slot-scope="scope">
            <el-input size="small"  v-model="scope.row.min" placeholder="请输入" @blur="handleSaveSetComp(scope.row)" />
          </template>
        </el-table-column>
        <el-table-column align="center" label="单位" prop="unit"/>
        <el-table-column align="center" label="精度" prop="precision"/>
        <el-table-column align="center" label="公式" prop="calculationFormula" show-overflow-tooltip></el-table-column>
        <el-table-column align="center" label="是否使用">
            <template slot-scope="scope">
            <el-tag type="success" size="small" v-if="scope.row.sign == 1">已使用</el-tag>
            <el-tag type="danger" size="small" v-if="scope.row.sign != 1">未使用</el-tag>
            </template>
        </el-table-column>
        <el-table-column align="center" label="是否收敛" >
            <template slot-scope="scope">
            <el-tag type="success" size="small" v-if="scope.row.comP_CON == 1">是</el-tag>
            <el-tag type="danger" size="small" v-if="scope.row.comP_CON != 1">否</el-tag>
            </template>
        </el-table-column>
        </el-table>
    </div>
</template>
<script>
import {GetInstrumentCOMPByModeId,QueryCOMP,setQueryCOMP} from '@/api/https'
export default({
    props:{
        height:{
            type:String,
            default:''
        },
        instrumentModelID:{
            type:[Number,String],
            default:0
        },
        isSet:{
            type:Boolean,
            default:false
        },
        instR_ID:{
            type:[Number,String],
            default:0
        }
    },
    data() {
        return{
            tableList:[]
        }   
    },
    mounted(){
         this.getTableListData()
    },
    watch:{
        'instrumentModelID':{
            handler(newVal,oldVal){
                if(newVal){
                    this.getTableListData()
                }else{
                    this.tableList = []
                }
            }
        },
    },
    methods:{
        getTableListData(){        
            if(this.isSet){
                 QueryCOMP({
                    InstrumentModelID:this.instrumentModelID,
                    INSTR_ID:this.instR_ID
                }).then(res=>{
                    if(res.isSuccess){
                        this.tableList = res.data || []
                    }else{
                        this.$message.error(res.errorMessage)
                    }
                })
            }else{
                GetInstrumentCOMPByModeId(this.instrumentModelID).then(res=>{
                    if (res.isSuccess) {
                        this.tableList = res.data || [];
                    }
                });
            }           
        },
        handleSaveSetComp(data){
            setQueryCOMP({
                id:data.id,
                INSTR_ID:data.INSTR_ID,
                COMPID:data.COMPID,
                max:data.max,
                min:data.min
            }).then(res=>{
                if(res.isSuccess){
                }else{
                    this.$message.error(res.errorMessage)
                }
            })
        },
    }
})
</script>
<style scoped>
.table-box{
    width: 100%;
    overflow: auto;
}
</style>
